package com.freewater.cargotracker.domain.model.voyage;

import org.apache.commons.lang3.Validate;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 航线调度好的具体航程：<br/>
 * 例如编号为"V100"的航线，2024-01-01从上海出发，2024-01-03到达日本东京；
 * 2024-01-05从日本东京出发，2024-01-20到达美国纽约；
 */
public class Schedule implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final Schedule EMPTY = new Schedule();

    private List<CarrierMovement> carrierMovements = Collections.emptyList();

    public Schedule() {

    }

    public Schedule(List<CarrierMovement> carrierMovements) {
        Validate.notNull(carrierMovements, "CarrierMovement are required");
        Validate.noNullElements(carrierMovements, "CarrierMovement can not be null");

        this.carrierMovements = carrierMovements;
    }

    public List<CarrierMovement> getCarrierMovements() {
        return Collections.unmodifiableList(carrierMovements);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Schedule)) return false;
        Schedule schedule = (Schedule) o;
        return sameValueAs(schedule);
    }

    private boolean sameValueAs(Schedule other) {
        return other != null
                && carrierMovements.equals(other.carrierMovements);
    }

    @Override
    public int hashCode() {
        return Objects.hash(carrierMovements);
    }
}
